package com.gw.jpa.controller;

import com.gw.jpa.entity.Student;
import com.gw.jpa.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student") //定义模块名称
public class StudentController { //控制器：接收前端的请求，把后端处理结果返回给前端
    @Autowired //依赖的自动注入
    StudentService studentService;
    @PostMapping("")
    public Student addStudent(Student student){

        //调用业务逻辑层，添加student信息
        return studentService.addStudent(student);
    }

    @GetMapping("/{sid}")
    public Student getStudent(@PathVariable("sid") Integer sid){

        //调用业务逻辑层，通过sid获取指定的student信息
        return studentService.getStudent(sid);
    }

    @GetMapping("")
    public List<Student> getStudentJquery(){

        //调用业务逻辑层，获取student全部信息
        return studentService.getStudentJquery();
    }

    @PutMapping("")
    public Student updateStudent(Student student){

        //调用业务逻辑层，通过sid更新指定的学生信息
        return studentService.updateStudent(student);
    }

    @DeleteMapping("{sid}")
    public void deleteStudent(@PathVariable("sid") Integer sid){

        //调用业务逻辑层，通过sid删除指定的学生信息
       studentService.deleteStudent(sid);
    }
}
